#include "util.hpp"
#include "data.hpp"
#include "server.hpp"

void file_test()
{
  aod::FileUtil("./test").CreateDirectory();
  aod::FileUtil("./test/test.txt").SetContent("hello my util");
  std::string body;
  aod::FileUtil f_util("./test/test.txt");
  f_util.SetContent("hello my video");
  f_util.GetContent(&body);
  std::cout << "body: " << body << std::endl;

  return;
}

void json_test()
{
  Json::Value val;
  val["姓名"] = "小张";
  val["年龄"] = 18;
  val["成绩"].append(98); 
  val["成绩"].append(99);
  val["成绩"].append(100);
  std::string std_ret;
  aod::JsonUtil::Serialize(val, &std_ret);
  std::cout << "ret: " << std_ret << std::endl;
  Json::Value json_ret;
  aod::JsonUtil::Deserialize(std_ret, &json_ret);
  std::cout << json_ret["姓名"].asString() << std::endl;
  std::cout << json_ret["年龄"].asString() << std::endl;
  for(auto a : json_ret["成绩"])
  {
    std::cout << a.asInt() << ' ';
  }
  std::cout << std::endl;
  return;
}

void tb_video_test()
{
  aod::TableVideo tb_video;
  Json::Value video;
  video["name"] = "大白来了";
  video["info"] = "大白打败大白";
  video["video"] = "/video/dabai.mp4";
  video["image"] = "/image/dabai.jpg";

  //tb_video.Insert(video);
  //tb_video.Insert(video);
  //tb_video.Delete(1);
  Json::Value new_video;
  new_video["name"] = "环太平洋";
  new_video["info"] = "这是最棒的";
  tb_video.Update(5,new_video);

  Json::Value videos;
  tb_video.SelectAll(&videos);
  for(auto &i : videos)
  {
    std::string ret;
    aod::JsonUtil::Serialize(i,&ret);
    std::cout << "result: " << ret << std::endl;
  }
  //tb_video.Delete(4);

}

void server_test()
{
  aod::Server server(9090);
  server.RunModule();
}
int main()
{
  //file_test();
  //json_test();
  //tb_video_test();
  server_test();
  return 0;
}
